﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using org.pdfbox.util;
using org.pdfbox.pdmodel;

namespace CopySniffer.UI.Core.FileLoad
{
    public class PdfFileLoader : IFileLoader
    {
        private readonly string[] supportedExtensions = { "pdf" };

        #region IFileLoader Members

        public IEnumerable<string> SupportedExtensions
        {
            get { return supportedExtensions; }
        }

        public string TypeAlias
        {
            get { return "Adobe Acrobat Document"; }
        }

        public string LoadFile(string fileName)
        {
            string s;
            PDDocument doc = null;
            try
            {
                doc = PDDocument.load(fileName);
                PDFTextStripper stripper = new PDFTextStripper();
                s = stripper.getText(doc);
            }
            finally
            {
                if (doc != null)
                {
                    doc.close();
                }
            }
            return s;
        }

        #endregion
    }
}
